//
//  NewsReaderPhoneViewController.m
//  NewsReaderPhone
//
//  Created by lang langhonglin on 10-8-17.
//  Copyright hgzp 2010. All rights reserved.
//

#import "NewsReaderPhoneViewController.h"

@implementation NewsReaderPhoneViewController

@synthesize  webView,navBar,toolBar,articleview,pageView,lableTitle;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	webView.delegate = self;
	NSString *path = @"http://www.dp.hgzp.com.cn/m/mindex.aspx";
	//NSString *path = @"http://www.dp.hgzp.com.cn/m/login.aspx";
	//NSString *path = @"http://www.dp.hgzp.com.cn/m/phonearticle.htm";
    NSURL *url = [NSURL URLWithString:path];
	[webView loadRequest:[NSURLRequest requestWithURL:url]];
	//[self setNavTitle:@"参考消息"];
	status = STATUS_DAODU;
	
		
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


//原版
-(IBAction) action_daodu {

	//[ webView stringByEvaluatingJavaScriptFromString:@"ExpandList()"];

	 lableTitle.text = @"参考消息";
	 status = STATUS_DAODU;
}


//RSS
-(IBAction) action_fav {
	
	 lableTitle.text = @"我的收藏";
	 status = STATUS_FAV;

	
}

- (void) setNavTitle:(NSString *)navTitle {
	
	lableTitle.text = navTitle;
	
}

//返回上一页
-(IBAction) action_history {
	
    //[ webView stringByEvaluatingJavaScriptFromString:@"HistoryPage()"];
	[ webView goBack];
 //   NSLog(@"action_history");	
}

//显示版面选择对话框
-(IBAction) action_selectpage {
	
    [ webView stringByEvaluatingJavaScriptFromString:@"shownavban()"];
}

//显示评论
-(IBAction) action_showPingShu {
	
    [ webView stringByEvaluatingJavaScriptFromString:@"ShowPingShu('新闻评述')"];
}

//显示时事
-(IBAction) action_shiShi {
	
	 [ webView stringByEvaluatingJavaScriptFromString:@"ShowPingShu('时事纵横')"];
}

//显示经济
-(IBAction) action_jingJi {
	
	 [ webView stringByEvaluatingJavaScriptFromString:@"ShowPingShu('世界经济')"];
}

//显示军事
-(IBAction) action_junShi {
	
  [ webView stringByEvaluatingJavaScriptFromString:@"ShowPingShu('军事·体育')"];
}

//显示头版
-(IBAction) action_touBan {
	
	[ webView stringByEvaluatingJavaScriptFromString:@"ShowPingShu('头版新闻')"];

}

//显示更多
-(IBAction) action_more {
	
	[ webView stringByEvaluatingJavaScriptFromString:@"ShowMorePage()"];
	
}



- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
	
	//return YES;
	NSURL *url = request.URL;
	NSString *urlString = url.absoluteString;
	if (navigationType == UIWebViewNavigationTypeLinkClicked)
	{
			
		
		/*if( status == STATUS_DAODU )
		{
			[self.pageView setUrlString:urlString];
			[self presentModalViewController:self.pageView animated:YES];
		}
		else {
			
			
			[self.articleview setUrlString:urlString];
			[self presentModalViewController:self.articleview animated:YES];
			
		}*/
		/*if ([urlString rangeOfString:@"login.aspx"].length > 0 
			|| [urlString rangeOfString:@"register.aspx"].length > 0 )
		{
			
			[self.pageView setUrlString:urlString];
			[self.pageView LoadUrlString:urlString];
			[self presentModalViewController:self.pageView animated:YES];
			return NO;
		}*/
		
		//if ([urlString rangeOfString:@".aspx"].length > 0 )
	
		if ([urlString rangeOfString:@"login.aspx"].length > 0 
			|| [urlString rangeOfString:@"register.aspx"].length > 0 
			|| [urlString rangeOfString:@"mcounter.aspx"].length > 0
			|| [urlString rangeOfString:@"mPayOrder.aspx"].length > 0 
			|| [urlString rangeOfString:@"Calendar.aspx"].length > 0 
			|| [urlString rangeOfString:@"MenuOp.aspx"].length > 0 
			|| [urlString rangeOfString:@"PageList.aspx"].length > 0 )
		 {
			 [self.pageView setUrlString:urlString];
			 [self.pageView LoadUrlString:urlString];
			 [self presentModalViewController:self.pageView animated:YES];
			 return NO;
		 }
		
		
		
		
		if ([urlString rangeOfString:@"ckxx"].length == 0 )
		{
			webView.scalesPageToFit = YES;
			return YES;
		}

	
		
		[self.articleview setUrlString:urlString];
		[self.articleview LoadUrlString:urlString];
		[self presentModalViewController:self.articleview animated:YES];

		return NO;
		
		
	}
	else {
		if ([urlString rangeOfString:@"PageList.aspx"].length > 0 )
		{
			[self.pageView setUrlString:urlString];
			[self.pageView LoadUrlString:urlString];
			[self presentModalViewController:self.pageView animated:YES];
			
			 return NO;
		}
	}

	//channelURL = urlString;
	return YES;
}


-(IBAction) action_BankView {
	
	[webView goBack];
	
}

-(IBAction) action_ReFresh {
	
	[webView reload];

	
}

-(void)  LoadUrlString:(NSString *)str {
	
	
	NSString *path = str;
    NSURL *url = [NSURL URLWithString:path];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
	
	
	
}



- (void)dealloc {
    [super dealloc];
}

@end
